Player = ExtendClass(MonoGameObject)

function Player:__init()
    self.speed = 10
    self.tilt = 5
    self.xMin = -6
    self.xMax = 6
    self.zMin = -4
    self.zMax = 8
    self.fireRate = 0.25
    self.nextFire = 0
    self.movement = Vector3()
end

function Player:OnGetAddr()
    return "Done_Player"
end

function Player:Start()
    --临时逻辑
    local gameObject = GameObject.Find("Game Controller")
    gameObject:SendMessage("OnPlayerInstantiateFinished")
end

function Player:OnIsUpdate()
    return true
end

function Player:Update()
    if Input.GetButton("Fire1") and Time.time > self.nextFire then
        self.nextFire = Time.time + self.fireRate;
        -- ADDRESSABLES UPDATES
        XResLua.CreateInstance("Done_Bolt", self.OnCreateBolt, self)
        local audio_source = EngineTool.GetComponent(self.gameObject, AudioSource)
        audio_source:Play()
    end
end

function Player:OnCreateBolt(gameObject)
    self.shotSpawn = self.shotSpawn or self:GetUObj("shotSpawn", Transform)
    gameObject.transform.position = self.shotSpawn.position
    gameObject.transform.rotation = self.shotSpawn.rotation
end

function Player:OnIsFixedUpdate()
    return true
end

function Player:FixedUpdate()
    self.moveHorizontal = Input.GetAxis ("Horizontal");
    self.moveVertical = Input.GetAxis ("Vertical");

    self.movement.x = self.moveHorizontal 
    self.movement.y = 0
    self.movement.z = self.moveVertical 

    local rigidbody = EngineTool.GetComponent(self.gameObject, Rigidbody)
    rigidbody.velocity = self.movement * self.speed
    
    self.movement.x = Mathf.Clamp (rigidbody.position.x, self.xMin, self.xMax)
    self.movement.z = Mathf.Clamp (rigidbody.position.z, self.zMin, self.zMax)
    rigidbody.position = self.movement
    
    rigidbody.rotation = Quaternion.Euler (0, 0, rigidbody.velocity.x * -self.tilt)--this generate more gc
end